#!/bin/bash
{
lld_cpu_tmp="$(ps axh o pcpu,pid,comm O-C |head)"       # CPU使用率，第一列数值的单位：%
lld_cpu_log=/home/myzabbix/zabbix.lld.cpu.log
echo "${lld_cpu_tmp}" |awk '{F[NR,1]=$1;F[NR,2]=$2;F[NR,3]=$3;B[$3]++}END{
for (i=1; i<11; i++) {
	for (j in B) {
		if (j==F[i,3])
			if (B[j]>1) print F[i,1],F[i,2]"_"F[i,3]; else print F[i,1],F[i,3]
		}
	}
}' > ${lld_cpu_log}

originData="$(awk '{p[$NF]++}END{
for (i in p) print "{\"{#CPUTOP}\":\""i"\"}";
}' ${lld_cpu_log})"
} 2>/dev/null
# 生成Json格式
echo "[`echo ${originData}|sed 's/ /,/g'`]"